package com.eonmind.user.converts;

import com.eonmind.common.provider.entity.user.NotificationType;
import com.eonmind.common.provider.entity.user.UserNotification;
import com.eonmind.user.dto.UserNoticeDto;
import jakarta.validation.constraints.NotNull;

import java.util.List;
import java.util.Map;

/**
 * @author Xujie
 * @since 2025/6/1 14:42
 **/


public class UserNoticeConvert {
    public static List<UserNoticeDto.UserNoticeData> toUserNoticeDataList(List<UserNotification> userNotificationList, Map<Long, NotificationType> notificationTypeMap) {
        return userNotificationList.stream().map(userNotification -> {
            UserNoticeDto.UserNoticeData userNoticeData = new UserNoticeDto.UserNoticeData();
            userNoticeData.setId(userNotification.getId());
            userNoticeData.setNoticeTitle(userNotification.getNoticeTitle());
            userNoticeData.setNoticeContent(userNotification.getNoticeContent());
            userNoticeData.setNoticeTags(toNoticeTagDataList(userNotification.getNoticeTags()));
            NotificationType notificationType = notificationTypeMap.get(userNotification.getNoticeTypeId());
            if (notificationType != null) {
                userNoticeData.setNoticeTypeName(notificationType.getNoticeTypeName());
                userNoticeData.setNoticeTypeId(notificationType.getId());
            }
            userNoticeData.setStatus(userNotification.getStatus());
            userNoticeData.setCreateTime(userNotification.getCreateTime());
            return userNoticeData;
        }).toList();
    }

    private static List<UserNoticeDto.UserNoticeData.NoticeTagData> toNoticeTagDataList(List<UserNotification.NoticeTag> noticeTags) {
        return noticeTags.stream()
                .map(t -> {
                    UserNoticeDto.UserNoticeData.NoticeTagData noticeTag = new UserNoticeDto.UserNoticeData.NoticeTagData();
                    noticeTag.setTagName(t.getTagName());
                    noticeTag.setTagStyle(t.getTagStyle());
                    return noticeTag;
                })
                .toList();
    }

    public static List<UserNotification.NoticeTag> toUserNoticeTagDataList(@NotNull List<com.eonmind.user.contract.dto.UserNoticeDto.UserSendNoticeRequest.NoticeTagData> noticeTags) {
        return noticeTags.stream().map(t -> {
            UserNotification.NoticeTag noticeTag = new UserNotification.NoticeTag();
            noticeTag.setTagName(t.getTagName());
            noticeTag.setTagStyle(t.getTagStyle());
            return noticeTag;
        }).toList();
    }
}
